<template>
  <el-container class="home_container">
    <el-header class="home_header">
      <div>
        <img src="../assets/heima.png" />
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="logOut">退出</el-button>
    </el-header>

    <el-container>

      <el-aside :width="handleWidth">
          <div class="toggle-button" @click="handleCollapse">|||</div>
        <el-menu
        :default-active="activePath"
        :router="true"
        :collapse-transition="false"
        :collapse="Collapsed"
        :unique-opened="true"
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
        >
          <el-submenu :index="'/'+item.path" v-for=" item in menuList" :key="item.id" >
            <template slot="title" >
              <i :class="iconObj[item.id]" ></i>
              <span>{{item.authName}}</span>
            </template>
             <el-menu-item :index="'/'+data.path" v-for="data in item.children" :key="data.id" @click="handleHighLight(data.path)">
            <i class="el-icon-menu"></i>
            <span slot="title">{{data.authName}}</span>
          </el-menu-item>
          </el-submenu>
          
         
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
    data(){
        return{
            menuList:[],
            Collapsed:false,
            iconObj:{
                '125':'iconfont icon-users',
                '103':'iconfont icon-tijikongjian',
                '101':'iconfont icon-shangpin',
                '102':'iconfont icon-danju',
                '145':'iconfont icon-baobiao'
            },
            activePath:''
            
        }
    },
    created(){
        this.activePath=sessionStorage.getItem("highlight")
        this.getMenuList()
        // console.log(this.activePath)
    },
  methods: {
    logOut() {
      sessionStorage.clear();
      this.$router.push("./login");
    },
    getMenuList(){
       this.$http.get('menus').then(res=>{
           if(res.data.meta.status===200){
          this.menuList=res.data.data
        //   console.log(this.menuList)
          }
          else{
              return this.$message.error(res.data.meta.msg)
          }

       })
   },
   handleCollapse(){
       this.Collapsed=!this.Collapsed

   },
   handleHighLight(path){
       sessionStorage.setItem("highlight","/"+path)
       this.activePath="/"+path

   }
    
   
   
  },
  computed:{
      handleWidth(){
          if(this.Collapsed===true){
              return 'auto'
          }
          else{
              return '200px'
          }
      },
      
     
  }
   
};
</script>

<style lang="less" scoped>
.home_header {
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
}
.home_container {
  height: 100%;
  
}
.el-header {
  background-color: #373d41;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    > span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #333744;
  .el-menu{
      border-right: none;
  }
 
  
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  
  
}
.toggle-button{
    background-color: #4a5064;
    text-align: center;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    letter-spacing: 0.2em;
    cursor: pointer;
}






</style>